import time

from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.touch_action import TouchAction
class Test_Page():
    def __init__(self,driver):
        self.driver = driver
    def test_Page(self):
        # 开发脚本27
        # 增强脚本：1.将旧的api方法替换最新的方式  2.添加等待方式
        # time.sleep(2)
        # 点击不在提示
        el1 = self.driver.find_element(MobileBy.ID, "com.meituan.phoenix:id/btn_choice_city")
        el1.click()
        # time.sleep(5)
        # 点击搜索框
        el2 = self.driver.find_element(MobileBy.XPATH,
                                  "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[1]/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[9]")
        el2.click()
        # time.sleep(2)
        # 点击输入框
        el3 = self.driver.find_element(MobileBy.XPATH,
                                  "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.EditText")
        el3.click()
        # time.sleep(2)
        # 输入北京
        el3.send_keys("北京")
        time.sleep(5)
        # 选择第一个
        el4 = self.driver.find_element(MobileBy.XPATH,
                                  "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup[1]/android.view.ViewGroup[1]")
        el4.click()
        time.sleep(10)
        # 向下滑动5次
        for i in range(5):
            time.sleep(2)
            TouchAction(self.driver).long_press(x=395, y=1250).move_to(x=405, y=583).release().perform()
        time.sleep(10)

